/*
 *    Copyright 2008-2009 The PoCo Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.asemantics.poco.parser.xml;

import java.net.URL;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.asemantics.poco.Entry;
import com.asemantics.poco.Response;
import com.asemantics.poco.parser.ResponseDataProvider;
import com.asemantics.poco.tests.BeanComparator;
import com.asemantics.poco.tests.ComparisonReport;

/**
 * 
 * @author Simone Tripodi
 * @author Michele Mostarda
 * @version $Id: XmlPoCoParserTestCase.java 264 2009-12-20 01:35:31Z simone.tripodi@gmail.com $
 */
public class XmlPoCoParserTestCase {

    protected XmlPoCoParser poCoXmlParser;

    @BeforeClass
    public void setUp() {
        this.poCoXmlParser = new XmlPoCoParser();
    }

    @AfterClass
    public void tearDown() {
        this.poCoXmlParser = null;
    }

    @Test(
            dataProvider = "createResponseDataProvider",
            dataProviderClass = ResponseDataProvider.class
    )
    public void testParsingFromXmlFormat(Response expected) throws Exception {
        URL resource = this.getClass().getResource("response.xml");

        Response actual = this.poCoXmlParser.parse(resource.openStream());

        int i = 0;
        for (Entry expectedEntry : expected.getEntries()) {
            ComparisonReport report = BeanComparator.compareBeans(expectedEntry, actual.getEntries().get(i));
            assert !report.isDifferent() : report.toString();
            i++;
        }

        assert expected.equals( actual ) : "Global equality failure.";
    }

}
